package com.wandian.audio.mvvm.audioauthorrank;

import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ActivityUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.audio.R;
import com.wandian.audio.adapter.AudioAuthorRankRecycleAdapter;
import com.wandian.audio.databinding.AudioActivityAuthorRankBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 作者排行activity
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_AUDIO_AUTHOR_RANK)
public class AudioAuthorRankActivity extends BaseMVVMActivity<AudioAuthorRankActivityViewModel> {
    private AudioActivityAuthorRankBinding dataBinding;
    private AudioAuthorRankRecycleAdapter audioAuthorRankRecycleAdapter;
    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.audio_activity_author_rank);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        initRecycle();
        initViewData();
        initClink();
        mViewModel.getMusicRank();
    }

    private void initRecycle(){
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
        dataBinding.recycler.setLayoutManager(layoutManager);
        audioAuthorRankRecycleAdapter  = new AudioAuthorRankRecycleAdapter(R.layout.audio_item_author_list_view);
        dataBinding.recycler.setAdapter(audioAuthorRankRecycleAdapter);
    }

    private void initViewData(){
        ActivityUtil.getInstance().showStatusView(this,dataBinding.viewSysTop,true);
        dataBinding.bindTransparentToolBar.toolBarTvTitle.setText("作者榜");
        mViewModel.listData.observe(this,rankBean->{
            if(!UIUtils.isEmpty(rankBean)){
                audioAuthorRankRecycleAdapter.setNewData(rankBean);
            }
        });
    }

    private void initClink(){
        dataBinding.bindTransparentToolBar.toolBarIvBack.setOnClickListener(v -> {
            finish();
        });
    }



}
